{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "use std::collections::HashMap;\n",
    "\n",
    "let mut map = HashMap::new();\n",
    "assert_eq!(map.insert(37, \"a\"), None);\n",
    "assert_eq!(map.is_empty(), false);\n",
    "\n",
    "map.insert(37, \"b\");\n",
    "assert_eq!(map.insert(37, \"c\"), Some(\"b\"));\n",
    "assert_eq!(map[&37], \"c\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/uncommon-words-from-two-sentences\n",
    "\n",
    "\n",
    "\n",
    "Runtime: 0 ms, faster than 100.00% of Rust online submissions for Uncommon Words from Two Sentences.\n",
    "Memory Usage: 2.1 MB, less than 38.46% of Rust online submissions for Uncommon Words from Two Sentences.\n",
    "\n",
    "\n",
    "\n",
    "```rust\n",
    "use std::collections::HashMap;\n",
    "\n",
    "pub struct Solution {}\n",
    "\n",
    "fn updateCounter(counter: &mut HashMap<String, u32>, l: &Vec<&str>) {\n",
    "    for word in l.to_owned() {\n",
    "        if counter.contains_key(word) {\n",
    "            counter.insert(word.to_string(), counter[word] + 1);\n",
    "        } else {\n",
    "            counter.insert(word.to_string(), 1 as u32);\n",
    "        }\n",
    "    }\n",
    "}\n",
    "\n",
    "impl Solution {\n",
    "    pub fn uncommon_from_sentences(a: String, b: String) -> Vec<String> {\n",
    "        let mut counter: HashMap<String, u32> = HashMap::new();\n",
    "        let aList = a.split(\" \").collect::<Vec<&str>>();\n",
    "        let bList = b.split(\" \").collect::<Vec<&str>>();\n",
    "        let mut r: Vec<String> = Vec::new();\n",
    "        updateCounter(&mut counter, &aList);\n",
    "        updateCounter(&mut counter, &bList);\n",
    "        for (key, value) in counter.into_iter() {\n",
    "            if value == 1 {\n",
    "                r.push(key.to_string());\n",
    "                //println!(\"{}\", key.to_string());\n",
    "            }\n",
    "        }\n",
    "        return r;\n",
    "    }\n",
    "}\n",
    "\n",
    "fn main() {\n",
    "    Solution::uncommon_from_sentences(\n",
    "        String::from(\"this apple is sweet\"),\n",
    "        String::from(\"this apple is sour\"),\n",
    "    );\n",
    "}\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Rust",
   "language": "rust",
   "name": "rust"
  },
  "language_info": {
   "codemirror_mode": "rust",
   "file_extension": ".rs",
   "mimetype": "text/rust",
   "name": "Rust",
   "pygment_lexer": "rust",
   "version": ""
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
